package information;

import java.util.Set;

/**
 * User, with all user attributes needed for user stories.
 * @author Christian	
 *
 */

public class User {

	private Usertype myUsertype;

	private Set<Park> myParks;

	private String myName;

	private String myEmail;

	private String myPhone;

	private boolean myBlackballStatus;
	
	/**
	 * Parameterized constructor. Constructs a user with data passed in.
	 * @param theUsertype	The usertype of this user.
	 * @param theParks		The parks belonging to this user (park manager).
	 * @param theName		The name of this user.
	 * @param theEmail		The email address of this user.
	 * @param thePhone		The phone number of this user.
	 * @param theBlackballStatus	The blackball status of this user.
	 */
	public User(final Usertype theUsertype, final Set<Park> theParks,
			final String theName, final String theEmail, final String thePhone,
			final boolean theBlackballStatus) {
		myUsertype = theUsertype;
		myParks = theParks;
		myName = theName;
		myEmail = theEmail;
		myPhone = thePhone;
		myBlackballStatus = theBlackballStatus;
	}
	
	public Usertype getUsertype() {
		return myUsertype;
	}
	
	public Set<Park> getParks() {
		return myParks;
	}
	
	public String getName() {
		return myName;
	}
	
	public String getEmail() {
		return myEmail;
	}
	
	public String getPhone() {
		return myPhone;
	}
	
	public boolean isBlackballed() {
		return myBlackballStatus;
	}
	
	public void setBlackballed() {
		myBlackballStatus = true;
	}
	
	/**
	 * Method for getting a park belonging to this Park Manager based on a park name.
	 * @param parkName The name of the park to check if this Park Manager has it
	 * @return The park belonging to this User or null if no park found matching the name
	 */
	//@requires parkName != null
	public Park getPark(final String parkName) {
		for (Park park : myParks) {
			if (park.getMyName().equals(parkName)) return park;
		}
		return null;
	}
	
	/**
	 * Checks if two users are the same.
	 */
	//@requires theUser != null
	//@ensures these two users are either equal or not equal
	@Override
	public boolean equals(final Object theUser) {
		boolean result = false;
		if (this == theUser) {
			result = true;
		} else if ((theUser instanceof User) &&
				(getClass() == theUser.getClass()) &&
				myName.equals(((User) theUser).getName()) &&
				myEmail.equals(((User) theUser).getEmail()) &&
				myPhone.equals(((User) theUser).getPhone())) {
			result = true;			
		}
		return result;
	}
}
